/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qltv;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author ThaoLe
 */
public class connect {

    private final String server = "THAOLE-VAIO";
    private final int port = 1433;
    private final String databaseName = "QLTHUVIEN_Nhom7_DACNPM";
    private final String username = "test";
    private final String password = "123456";
    Connection con = null;
    public Connection connect() {
        
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch(ClassNotFoundException e) {
            System.out.println("Khong tim thay Driver cho SQL Server 2005");
            e.printStackTrace();
        }
        try {
            con = DriverManager.getConnection(getURLConnection());
        } catch(SQLException e) {
            System.out.println("Khong ket noi duoc voi database");
            System.out.println(e.getMessage());
        }
        return con;
    }
    private String getURLConnection() {
        return "jdbc:sqlserver://" + server + ":" + port +
                ";databaseName=" + databaseName +
                ";User=" + username +
                ";Password=" + password;
    }
    ResultSet executeSQL(String querySQL) throws SQLException{
        Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rs = stmt.executeQuery(querySQL);
        return rs;
    }
    
}